<?php
	header("Content-Type: text/html;charset=utf-8");
	include("function/_nosql.php"); //
	include("function/function.php");
	include("_include.user.judge.php");
	$kboy_userid = $_SESSION['kboy_userid'];
	$kboy_user = $_SESSION['kboy_user'];
	$user_passcode = chkstr(trim($_REQUEST['user_passcode']));
	$id = chkstr(trim($_REQUEST['id']));
	$aid = chkstr(trim($_REQUEST['aid']));
	$action = chkstr(trim($_REQUEST['action']));
	$travel_title = chkstr(trim($_REQUEST['travel_title']));
	$travel_bigclass = chkstr(trim($_REQUEST['travel_bigclass']));
	$travel_pic = chkstr(trim($_REQUEST['travel_pic']));
	$travel_content = addslashes($_REQUEST['travel_content']);
	$urlcode = trim($_POST['urlcode']);
	$urls = urldecode($urlcode);
	
	if($action == "add"){
	    $kboy_qq_login = $_SESSION['kboy_qq_login'];
	    if(getClassName("kboy_user","user_hei","user_qq_openid='$kboy_qq_login'") == 1){
            echo erro("由于你发布不良信息 ，管理员已经已经把你拉黑！");
        }
        if(getClassName("kboy_user","user_hei","uid='$kboy_userid'") == 1){
            echo erro("由于你发布不良信息 ，管理员已经已经把你拉黑！");
        }
	    $newstime =  getNewstime("kboy_forum_travel","travel_addtime","uid='$kboy_userid'");
	    $i = 0;
	    foreach($newstime['time'] as $k => $v){
	        $i++;
	        $xctime = diffSeconds($newstime['time'][$i],$newstime['time'][$k]);
	        if($xctime < 60){
	            $ea .= 1;
	        }
	    }
	    if($ea == 111){
	        mysql_query("update kboy_user set user_hei = 1 where uid = '$kboy_userid'");
	        // 删除数据
			$mysql = new sqlstr("kboy_news"); 
			$news_sql = $mysql -> deleteSql("id in($newsid)");
			$news_res = mysql_query($news_sql);
	        echo erro("由于你发布平率过快 ，管理员已经已经把你拉黑！并删除相关游记");
	    }
	    if($user_passcode != $_SESSION['verifyCode']){
			echo erro("验证码错误！");
		}
		if(strlen($travel_title)<1){
			echo erro("游记标题不能为空！");
		}
		if(strlen($travel_pic)<1){
			echo erro("游记主图不能为空！");
		}
		if(strlen($travel_bigclass)<1){
			echo erro("请选择板块分类！");
		}
		if(!is_numeric($travel_bigclass)){
			echo erro("请选择板块分类");
		}

		// 添加内容
		$mysql = new sqlstr("kboy_forum_travel"); 
		$mysql -> set("travel_title",$travel_title);
		$mysql -> set("aid",$aid);
		$mysql -> set("travel_bigclass",$travel_bigclass,true);
		$mysql -> set("travel_pic",$travel_pic);
		$mysql -> set("travel_content",$travel_content);
		$mysql -> set("uid",$kboy_userid);
		$news_sql = $mysql -> insertSql();
		$news_res = mysql_query($news_sql);
		if($news_res){
		    $_SESSION['verifyCode'] = '';
			echo ok("操作成功",$urls);
		}else{
			echo erro("服务器内部错误");
		}
	}elseif($action == "edit"){
		if(strlen($id)<1){
			echo erro("ID错误！");
		}
		if(!is_numeric($id)){
			echo erro("ID错误！");
		}
		if(strlen($travel_title)<1){
			echo erro("游记标题不能为空！");
		}
		if(strlen($travel_bigclass)<1){
			echo erro("请选择板块分类！");
		}
		if(!is_numeric($travel_bigclass)){
			echo erro("请选择板块分类");
		}

		// 修改内容
		$mysql = new sqlstr("kboy_forum_travel"); 
		$mysql -> set("travel_title",$travel_title);
		$mysql -> set("travel_bigclass",$travel_bigclass,true);
		$mysql -> set("travel_pic",$travel_pic);
		$mysql -> set("travel_content",$travel_content);
		$news_sql = $mysql -> updateSql("uid=$kboy_userid and id=$id");
		$news_res = mysql_query($news_sql);
		if($news_res){
			echo ok("操作成功","forum_travel.php?uid=$kboy_userid");
		}else{
			echo erro("服务器内部错误");
		}
	
	}else{
		echo erro("参数错误");
	}
?>